const dictKey = 'DICT'

export function setDict(dict){
    localStorage.setItem(dictKey, JSON.stringify(dict))
}
export function getDict(){
    return  JSON.parse(localStorage.getItem(dictKey))
}
export function removeDict(){
    localStorage.removeItem(dictKey)
}
export function getDictsByType(type ) {
    let res = [] 
    getDict().forEach( item => {
        if (item.type === type) {
            res.push(item)
        }
    })
    return res
}
export function getOneDict(params ) {
    const { type, value } = params
    let res = {} 
    getDict().forEach( item => {
        if (item.type === type && item.value === value) {
            res = item
        }
    })
    return res
}
